﻿using UnityEngine;

namespace Framework
{
    public static class CoordConvert
    {
        public static int Pos2Cod(float pos)
        {
            return Mathf.FloorToInt(pos);
        }
        public static int CodX2Cnk(int cod)
        {
            return cod / Chunk.size.x;
        }
        public static int CodY2Cnk(int cod)
        {
            return cod / Chunk.size.y;
        }
        public static int CodZ2Cnk(int cod)
        {
            return cod / Chunk.size.z;
        }
        public static int PosX2Cnk(float pos)
        {
            return CodX2Cnk(Pos2Cod(pos));
        }
        public static int PosY2Cnk(float pos)
        {
            return CodY2Cnk(Pos2Cod(pos));
        }
        public static int PosZ2Cnk(float pos)
        {
            return CodZ2Cnk(Pos2Cod(pos));
        }
        public static int CnkX2Cod(int cnk)
        {
            return cnk * Chunk.size.x;
        }
        public static int CnkY2Cod(int cnk)
        {
            return cnk * Chunk.size.y;
        }
        public static int CnkZ2Cod(int cnk)
        {
            return cnk * Chunk.size.z;
        }
        public static Vector3Int Cnk2Cod(Vector3Int cnk)
        {
            return new Vector3Int(CnkX2Cod(cnk.x), CnkY2Cod(cnk.y), CnkZ2Cod(cnk.z));
        }
        public static Vector3 Cod2Pos(Vector3Int cod)
        {
            return new Vector3(cod.x, cod.y, cod.z);
        }
        public static Vector3 Cnk2Pos(Vector3Int cnk)
        {
            return Cod2Pos(Cnk2Cod(cnk));
        }
    }
}
